package org.example.sping02;

import org.example.sping02.dao.UserDao;
import org.example.sping02.entity.Person;
import org.example.sping02.entity.User;
import org.example.sping02.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Spring02Application {



        public static void main(String[] args) {
            ApplicationContext ioc = SpringApplication.run(Spring02Application.class, args);
            System.out.println("ioc容器启动完成-----");

            Person person1 = ioc.getBean("person", Person.class);
            System.out.println(person1);


            Person person2 = ioc.getBean("person", Person.class);
            System.out.println(person2);

        }

        public static void main5(String[] args) {
            ApplicationContext ioc = SpringApplication.run(Spring02Application.class, args);

            UserDao userDao = ioc.getBean("userDao", UserDao.class);
            userDao.add();

            UserService userService = ioc.getBean(UserService.class);
            userService.add();

        }
        public static void main3(String[] args) {
            ApplicationContext ioc = SpringApplication.run(Spring02Application.class, args);

            System.out.println("ioc容器启动完成");
            User bean = ioc.getBean(User.class);
            System.out.println(bean);

            User bean2 = ioc.getBean(User.class);
            System.out.println(bean2);

        }


        public static void main2(String[] args) {
            ApplicationContext ioc = SpringApplication.run(Spring02Application.class, args);
            String[] beanDefinitionNames = ioc.getBeanDefinitionNames();
            for (String name : beanDefinitionNames) {
                System.out.println(name + "..");
            }
        }

        public static void main1(String[] args) {
            // 启动springboot 容器

            ApplicationContext ioc= SpringApplication.run(Spring02Application.class, args);
            // 字节码获取对象


            User user=  ioc.getBean("user1",User.class);
            System.out.println(user);
        }

    }


